package com.swind.fast.modules.app.halali.partner.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.swind.fast.common.api.vo.Result;
import com.swind.fast.common.system.query.QueryGenerator;
import com.swind.fast.common.util.oConvertUtils;
import com.swind.fast.common.constant.CommonConstant;
import com.swind.fast.modules.app.halali.partner.entity.RestaurantCategory;
import com.swind.fast.modules.app.halali.partner.service.IRestaurantCategoryService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import com.swind.fast.common.system.base.controller.SwindController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
// import com.swind.fast.common.aspect.annotation.AutoLog;

import com.swind.fast.modules.system.entity.SysAnnouncement;
import com.swind.fast.modules.system.entity.SysAnnouncementSend;
import com.swind.fast.modules.system.service.ISysAnnouncementSendService;
import com.swind.fast.modules.system.service.ISysAnnouncementService;

import com.swind.fast.modules.app.halali.partner.vo.request.RankInfoVo;
import com.swind.fast.modules.app.halali.partner.vo.request.CategoryVo;
import com.swind.fast.modules.app.halali.partner.vo.request.CategoryUpdateVo;
import com.swind.fast.modules.app.halali.partner.vo.common.FileUploadVo;
import io.swagger.annotations.ApiParam;
import com.swind.fast.modules.app.halali.partner.component.HalaliUtils;

 /**
 * @Description: 餐厅
 * @Author: swind
 * @Date:   2022-01-20
 * @Version: V1.0
 */
@Api(tags="07.商户端-分类")
@RestController
@RequestMapping("/app/partner/restaurant/category")
@Slf4j
public class RestaurantCategoryController extends SwindController<RestaurantCategory, IRestaurantCategoryService> {

	@Autowired
	private HalaliUtils halaliUtils;

	@ApiOperation(value="分类-列表", notes="")
	@GetMapping(value = "/list")
	public Result<List<RestaurantCategory>> queryCategoryListAction() {
		List<RestaurantCategory> list = this.service.getCategoryList();
		return Result.OK(list);
	}

	@ApiOperation(value="分类-排序", notes="")
	@PostMapping(value = "/rank/update")
	public Result<?> rankUpdateAction(@RequestBody List<RankInfoVo> items) {
		this.service.updateRank(items);
		return Result.OK();
	}

	@ApiOperation(value="分类-添加", notes="")
	@PostMapping(value = "/add")
	public Result<RestaurantCategory> addAction(@RequestBody CategoryVo item) {
		RestaurantCategory cat = this.service.saveMain(item);
		return Result.OK(cat);
	}

    @ApiOperation(value="分类-修改", notes="")
    @PostMapping(value = "/update/info")
    public Result<RestaurantCategory> updateAction(@RequestBody CategoryUpdateVo item) {
        RestaurantCategory cat = this.service.updateInfo(item);
        return Result.OK(cat);
    }

	@ApiOperation(value="分类-图片")
    @PostMapping(value = "/update/image")
    public Result<FileUploadVo> updatePic(
            @ApiParam(name ="file",type="MultipartFile",value="image.jpg",example="image.jpg",required=true)
            @RequestParam(name="file", required=true) MultipartFile file
            ) {
        String bizPath = "halali/restaurant/category";
        FileUploadVo fileVo = halaliUtils.uploadLocal(file, bizPath);
        return Result.OK(fileVo);
    }

	@ApiOperation(value="分类-删除", notes="")
	@DeleteMapping(value = "/delete")
	public Result<?> removeAction(@RequestParam(name="id",required=true) String id) {
		this.service.removeById(id);
		return Result.OK();
	}
}
